local yunming = fk.CreateSkill {
  name = "th_yunming",
}

yunming:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yunming.name) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = yunming.name, 
      cancelable = true,
      prompt = "#th_yunming-ask::" .. target.id .. ":" .. data.reason
    })
    if #card ~= 0 then
      event:setCostData(self, { cards = card })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    room:changeJudge{
      data = data,
      player = player, 
      card = Fk:getCardById(dat.cards[1]),
      skillName = yunming.name,
      exchange = true
    }
  end,
})
yunming:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yunming.name) and
    data.card and data.card.type ~= Card.TypeEquip and #Card:getIdList(data.card) ~= 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = yunming.name,
      prompt = "#th_yunming-invoke"
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = yunming.name,
      pattern = ".|.|".. (data.card:getSuitString()),
    }
    room:judge(judge)
    if judge:matchPattern() then
      data.disresponsiveList = player.room:getAlivePlayers(false)
    end
  end,
})

Fk:loadTranslationTable{
  ["th_yunming"] = "运命",
  [":th_yunming"] = "一名角色的判定牌生效前，你可以用一张牌替换之；你使用非装备非虚拟牌时，你可以判定，若与此牌花色相同则此牌不可响应。",

  ["#th_yunming-ask"] = "运命：你可以用一张牌替换 %dest 的 %arg 判定",
  ["#th_yunming-invoke"] = "运命：你可以判定，若与此牌花色相同则此牌不可响应。",
}

return yunming